home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / AMOSList / AMOSLIST.0897 / 000107_amos-request@svcs1.digex.net_Fri Aug 8 18:14:43 1997.msg < prev    next >
Text File  |  1997-09-09  |  3KB  |  108 lines

  1. Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
  2.     by mail3.access.digex.net (8.8.5/8.8.5) with ESMTP id SAA05173
  3.     for <mcox@access.digex.net>; Fri, 8 Aug 1997 18:14:42 -0400 (EDT)
  4. Received: (from daemon@localhost)
  5.     by svcs1.digex.net (8.8.5/8.8.5) id OAA00670
  6.     for amos-out; Fri, 8 Aug 1997 14:43:36 -0400 (EDT)
  7. Received: from mail2.access.digex.net (mail2.access.digex.net [205.197.247.3])
  8.     by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id OAA00667
  9.     for <amos-list@svcs1.digex.net>; Fri, 8 Aug 1997 14:43:35 -0400 (EDT)
  10. Received: from dfw-ix7.ix.netcom.com (dfw-ix7.ix.netcom.com [206.214.98.7])
  11.     by mail2.access.digex.net (8.8.5/8.8.5) with ESMTP id OAA01261
  12.     for <amos-list@access.digex.net>; Fri, 8 Aug 1997 14:43:34 -0400 (EDT)
  13. Received: (from smap@localhost)
  14.           by dfw-ix7.ix.netcom.com (8.8.4/8.8.4)
  15.       id NAA11760 for <amos-list@access.digex.net>; Fri, 8 Aug 1997 13:43:01 -0500 (CDT)
  16. Received: from pit-pa3-25.ix.netcom.com(199.183.195.121) by dfw-ix7.ix.netcom.com via smap (V1.3)
  17.     id sma011743; Fri Aug  8 13:42:29 1997
  18. From: Garfield Benjamin <gbenjam@ix.netcom.com>
  19. Reply-To: Garfield Benjamin <gbenjam@ix.netcom.com>
  20. To: amos-list@access.digex.net
  21. Date: Fri, 08 Aug 1997 14:03:36 +0500
  22. Message-ID: <yam7159.1783.2795960@smtp.ix.netcom.com>
  23. X-Mailer: YAM 1.3.2 - Amiga Mailer by Marcel Beck
  24. Subject: Re: Rnd and Qrnd
  25. MIME-Version: 1.0
  26. Content-Type: text/plain
  27. Status: O
  28. X-Status: 
  29.  
  30. On 07-Aug-97, --==Murray==-- wrote:
  31.  
  32. >> Try storing your random values in an array first.  Then they'll be
  33. >> available whenever you need them.
  34.  
  35. >I'd thought of that but the thing is I need all sorts of different
  36. >arrays for different rnd(n)  values.
  37. >i.e. some calls are Rnd(10) some are Rnd(100) and some are
  38. >virtually any number in between.
  39.  
  40.    Hello.
  41.  
  42.    I too would recommend using a Rnd-Table .
  43.  
  44.    If you only need values between 0 and 100 then it would only
  45.    take a few hundred bytes (depending on how long you want
  46.    to go before the random-cycle repeats) to set-up the Rnd-
  47.    table.
  48.  
  49.    Now, you can either set up a slower, general-purpose routine...
  50.  
  51.    Dim RANDTABLE(100)
  52.    For REP=0 to 100
  53.       RANDTABLE(REP)=Rnd(100)
  54.    Next REP 
  55.  
  56.    ' Initialize the RAND-Pointer
  57.    RANDPOS=0 
  58.  
  59.    GENRAND:
  60.    RVALUE=RANDTABLE(RANDPOS)
  61.    If RVALUE>RANDMAX Then RVALUE=RVALUE Mod RANDMAX
  62.    Add RANDPOS,1,0 To 100
  63.    Return
  64.  
  65.    Simply load RANDMAX and call the routine. RVALUE will return a
  66.    value from 0 to RANDMAX
  67.  
  68.    
  69.    Or, you can create faster routines by simply precalculating 
  70.    several RndTables and writing more dedicated code.
  71.  
  72.    Dim RAND10TABLE(10),RAND100TABLE(100)
  73.    For REP=0 To 10
  74.       RAND10TABLE(REP)=Rnd(10)
  75.    Next REP
  76.    For REP=0 To 100
  77.       RAND100TABLE(REP)=Rnd(100)
  78.    Next REP
  79.  
  80.    RAND100POS=0 : RAND10POS=0
  81.  
  82.    RAND100:
  83.    RVALUE=RAND100TABLE(RAND100POS)
  84.    Add RAND100POS,1,0 To 100
  85.    Return
  86.  
  87.    RAND10:
  88.    RVALUE=RAND10TABLE(RAND10POS)
  89.    Add RAND10POS,1,0 To 10
  90.    Return
  91.  
  92.  
  93.    As Scott mentioned, accessing AMOS arrays is a bit slow. By 
  94.    switching from arrays to Bank-access, you can speed up the
  95.    RndCalls 30% or more and reduce the memory-requirements to
  96.    half as you can Doke and Deek 2-byte values for each of the
  97.    Random values, where AMOS uses long-words (4 bytes) for
  98.    all variables and arrays...
  99.  
  100.  
  101.  
  102.       Take Care,
  103.  
  104.        GARFIELD
  105.  
  106.  
  107.  
  108.